package com.emr.web.controller.emr;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.emr.common.annotation.Log;
import com.emr.common.enums.BusinessType;
import com.emr.module.domain.Icd;
import com.emr.module.service.IIcdService;
import com.emr.web.core.base.BaseController;
import com.emr.framework.web.page.TableDataInfo;
import com.emr.common.base.AjaxResult;

/**
 * 疾病编码字典 信息操作处理
 * 
 * @author emr
 * @date 2019-02-19
 */
@Controller
@RequestMapping("/module/icd")
public class IcdController extends BaseController
{
    private String prefix = "module/icd";
	
	@Autowired
	private IIcdService icdService;
	
	@RequiresPermissions("module:icd:view")
	@GetMapping()
	public String icd()
	{
	    return prefix + "/icd";
	}
	
	/**
	 * 查询疾病编码字典列表
	 */
	@RequiresPermissions("module:icd:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Icd icd)
	{
		startPage();
        List<Icd> list = icdService.selectIcdList(icd);
		return getDataTable(list);
	}
	
	/**
	 * 新增疾病编码字典
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存疾病编码字典
	 */
	@RequiresPermissions("module:icd:add")
	@Log(title = "疾病编码字典", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Icd icd)
	{		
		return toAjax(icdService.insertIcd(icd));
	}

	/**
	 * 修改疾病编码字典
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Integer id, ModelMap mmap)
	{
		Icd icd = icdService.selectIcdById(id);
		mmap.put("icd", icd);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存疾病编码字典
	 */
	@RequiresPermissions("module:icd:edit")
	@Log(title = "疾病编码字典", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Icd icd)
	{		
		return toAjax(icdService.updateIcd(icd));
	}
	
	/**
	 * 删除疾病编码字典
	 */
	@RequiresPermissions("module:icd:remove")
	@Log(title = "疾病编码字典", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(icdService.deleteIcdByIds(ids));
	}
	
}
